//
//  RecordViewController.m
//  VoSAT
//
//  Created by 王译 on 2018/4/22.
//  Copyright © 2018年 王. All rights reserved.
//

#import "RecordViewController.h"

@interface RecordViewController ()
{
    UITextField *numTextField;
    NSMutableString *muStr;
}
@end

@implementation RecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    muStr = [[NSMutableString alloc]init];
    UIView *topView = [UIView new];
    [self.view addSubview:topView];
    topView.sd_layout
    .topEqualToView(self.view)
    .centerXEqualToView(self.view)
    .widthRatioToView(self.view, 1)
    .heightRatioToView(self.view, 0.3);
    
    
    numTextField = [[UITextField alloc]init];
    numTextField.clearButtonMode = UITextFieldViewModeAlways;
    [self.view addSubview:numTextField];
    numTextField.font = [UIFont systemFontOfSize:25];
    numTextField.textAlignment = NSTextAlignmentCenter;
    numTextField.sd_layout
    .topSpaceToView(topView, 10)
    .centerXEqualToView(self.view)
    .widthRatioToView(self.view, 0.8)
    .heightIs(40);
    numTextField.placeholder = @"拨号或使用号码搜索";
//    numTextField.enabled = NO;
    [self numBtnCreate];
    
    // Do any additional setup after loading the view.
}

-(void)numBtnCreate{
    
    
    
    NSArray * numArr = @[@"1",@"2",@"3",
                         @"4",@"5",@"6",
                         @"7",@"8",@"9",
                         @"*",@"0",@"#"
                         ];
    
    CGFloat btnWidth = 80;
    CGFloat btnLeft = (ScreenWidth - 3 * btnWidth) / 4.0;
    
    for (int i = 0; i < numArr.count; i ++) {
        ZYButton * btn = [[ZYButton alloc]initWithTitle:numArr[i] font:[UIFont systemFontOfSize:35]];
        [btn setBackgroundImage:[UIImage imageNamed:@"btn_num"] forState:UIControlStateNormal];
//        btn.block = ^(NSString * reMark){
//
////            [self btnClickBtn:reMark];
//        };
        [self.view addSubview:btn];
        
        
        if (i != 9) {
            [btn setTitleEdgeInsets:UIEdgeInsetsMake(-8, 0, 0, 0)];
        }
        else{
            [btn setTitleEdgeInsets:UIEdgeInsetsMake(8, 0, 0, 0)];
        }
        
        btn.sd_layout
        .leftSpaceToView(self.view, i%3*(btnWidth+btnLeft)+btnLeft)
        .topSpaceToView(numTextField, i/3*(btnWidth+10)+20)
        .widthIs(btnWidth)
        .heightEqualToWidth();
        
        [btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];

    }
}

-(void)onClick:(UIButton *)btn{
    
    [muStr appendString:btn.titleLabel.text];
    numTextField.text = muStr;
    NSLog(@"%@",btn.titleLabel.text);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
